package com.shuai.frame.registry;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 本地注册中心
 */
@Slf4j
public class LocalRegister {
    private LocalRegister() {
    }

    /**
     * 模拟注册中心
     * key: Service.class.getName()
     * value: Service.class
     */
    private static final ConcurrentHashMap<String, Class<?>> localContainer = new ConcurrentHashMap<>();

    public static void register(String serviceName, Class<?> implClass) {
        log.info("注册了服务：[服务名称：{}]-[服务实现：{}]", serviceName, implClass);
        localContainer.put(serviceName, implClass);
    }

    public static Class<?> getService(String serviceName) {
        return localContainer.get(serviceName);
    }

    public static boolean remove(String serviceName) {
        return localContainer.remove(serviceName) != null;
    }
}
